package com.livestocksolutions;

import com.livestocksolutions.util.UpdateHistory;

/* -- Version History --
 *  1.0 : 11 July 2012 - Initial version.
 *  
 *  1.1 : 11 July 2012 - Moved String name, getName() and setName(String) from to Owner Class
 *  
 *  1.2 : 16 July 2012 - Class now implements Serializable
 *  
 *  1.3 : 24 September 2012 - Serialisation method no longer requires MedicalHistory implementing Serializable.
 */

/**
 * This class contains details for a Business that is used as a contact
 * @author Adam Parr
 * @version 1.3
 * 
 * @.modified 24 September 2012
 */
public class Business extends Owner {
	/**
	 * Address of the Business
	 */
	protected ContactAddress address;
	
	/**
	 * Constructor for creating a Business Owner
	 */
	public Business(){
		super();
	}
	
	/**
	 * Constructor
	 * @param id The id of the previous version of this Owner Object
	 */
	protected Business(long id){
		super(id);
	}
	
	/**
	 * Set the address of this Farm to the one provided
	 * @param address The new address to give to this Farm
	 */
	public void setAddress(ContactAddress address){
		this.address=address;
		update.put("ADDRESS", new UpdateHistory("true"));
	}
	
	/**
	 * Get the address of this Business
	 * @return Address of this Business
	 */
	public ContactAddress getAddress(){
		if(address!=null){
			return address;
		}
		for(ContactDetail c : contacts.values()){
			if(c instanceof ContactAddress){
				return (ContactAddress)c;
			}
		}
		return new ContactAddress();
	}
	
	/**
	 * Updates this Object with the updated values from the different version.
	 * @param changes Owner that represents this Object in a different version.
	 * @return <tt>true</tt> if changes is not null and changes does not equal this object, <tt>false</tt> otherwise.
	 */
	public boolean update(Business changes){
		if(changes!=null && this!=changes){
			super.update(changes);
			
			if(updateBefore("ADDRESS",changes)){
				address=changes.address;
				update.put("ADDRESS", new UpdateHistory("true"));
			}
			return true;
		}
		return false;
	}
}

